/**
 * @file categories/binary_tree/reconstruct_postorder/main.cpp
 * @brief
 * @see https://www.luogu.com.cn/problem/P1030
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/8 12:13:23
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 30;
char inorder[N], preorder[N];
int n;
void reconstruct(int preLeft, int preRight, int inLeft, int inRight) {
  if (preLeft < preRight && inLeft < inRight) {
    int root = preorder[preLeft];
    int mid = (find(inorder, inorder + n, root) - inorder) - inLeft;
    reconstruct(preLeft + 1, preLeft + 1 + mid, inLeft, inLeft + mid);
    reconstruct(preLeft + mid + 1, preRight, inLeft + mid + 1, inRight);
    putchar(root);
  }
}
int main() {
  // High rating and good luck!
  cin >> inorder >> preorder;
  n = strlen(inorder);
  reconstruct(0, n, 0, n);
  return 0;
}
